<template>
<!-- 购买数量子组件 -->
   <div class="mui-numbox" data-numbox-min='1' >
		<button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
		<input id="test" class="mui-input-numbox" type="number" value="1" @change="countChanged" ref="numbox" />
		<button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
	</div>
</template>


<script>
//导入mui
import mui from '../../lib/mui/js/mui.min.js'
export default {
  data(){
	  return {}
  },
  mounted(){
	  //初始化数量子组件
	  mui('.mui-numbox').numbox()
  },
  methods:{
	  countChanged(){
		  //console.log("ok")获取文本框的值，并传递给父组件
		  this.$emit("getcount",this.$refs.numbox.value)
	  }
  },
  props:["max"],
  watch:{"max":function(newVal){
	  //console.log(newVal)监听父组件传递过来的max
	  //设置最大值  mui 中numbox  js   api
	  mui(".mui-numbox").numbox().setOption('max',newVal)
  }}
}
</script>


<style lang="less" scoped>

</style>

